using System.Collections;
using EnvDTE;
using NUnit.Framework;
using NUnit.Mocks;

namespace NUnitGenAddIn.Core.Test
{
	[TestFixture]
	public class TestAddInHelper
	{
		private AddInHelper _unitUnderTest;
		private MockDTE _mockDTE;
		private DynamicMock _mockAddIn;

		[SetUp]
		public void SetUp()
		{
			_mockDTE = new MockDTE();
			MockDocument document = new MockDocument();
			MockProjectItem projectItem = new MockProjectItem();
			projectItem.SetFileCodeModel(new MockFileCodeModel(new MockCodeElements(new ArrayList()) ));
			document.SetProjectItem(projectItem);
			_mockDTE.SetActiveDocument(document);
			_mockAddIn = new DynamicMock(typeof (AddIn));
			_unitUnderTest = new AddInHelper(_mockDTE, (AddIn) _mockAddIn.MockInstance);
		}

		[TearDown]
		public void TearDown()
		{
			_mockAddIn.Verify();

			_unitUnderTest = null;
			_mockDTE = null;
			_mockAddIn = null;
		}

		[Test]
		public void TestExecuteCommand()
		{
			_unitUnderTest.ExecuteCommand("topMenuName", "subMenuCommand", "p_2");
			Assert.AreEqual("CommandName:topMenuName.subMenuCommand;CommandArgs:p_2", _mockDTE.Result,
			                "Arguments of ExecuteCommand are formatted wrong.");
		}

		[Test]
		public void TestGetActiveDocument()
		{
			Assert.IsNotNull(_unitUnderTest.GetActiveDocument(), "GetActiveDocument returns null");
		}

		[Test]
		public void TestGetClassListFromCodeElementList()
		{
			ArrayList list = new ArrayList
			                     {
			                         new MockCodeClass("testClass1"),
			                         new MockCodeClass("testClass2"),
			                         new MockCodeNamespace("testNamespace")
			                     };
		    Assert.AreEqual(2, _unitUnderTest.GetClassListFromCodeElementList(list).Count,
			                "GetClassListFromCodeElementList returns wrong number of CodeClass.");
		}

		[Test]
		[Ignore("Test in derived classes")]
		public void TestGetCodeClassFromCodeElements()
		{}

		[Test]
		[Ignore("Test in derived classes")]
		public void TestGetCodeElementListFromPoint()
		{}

		[Test]
		[Ignore("Test in derived classes")]
		public void TestAddCommandToCommandBar()
		{}
		
		[Test]
		public void TestGetCodeModel4CurrentProjectItem()
		{
			Assert.IsNotNull(_unitUnderTest.GetCodeModel4CurrentProjectItem()) ;
		}

		[Test]
		public void TestGetCurrentProject()
		{
			Assert.IsNotNull(_unitUnderTest.GetCurrentProject());
		}

		[Test]
		public void TestGetCurrentProjectItem()
		{
				Assert.IsNotNull(_unitUnderTest.GetCurrentProjectItem());
		}
}
}